import { MenuItem, OpenedMenu } from '/@/types/menu';
import { useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
  setUserMenu,
  setOpenKey,
  setselectMenuKey,
  addOpenedMenu,
  setCurrentPath,
  filterOpenKey,
  setCurrenFull,
  setBackRoute,
} from '../action';
import {
  getStateMenuList,
  getstateOpenMenuKey,
  getselectMenuKey,
  getStateOpenMenu,
  getStateCurrentPath,
  getStateCurrFull,
  getStateBackRoute,
} from '../getter/menu';
export const useStateMenuList = () => useSelector(getStateMenuList);
export const useStateOpenMenuKey = () => useSelector(getstateOpenMenuKey);
export const useStateselectMenuKey = () => {
  //处理详情高亮问题
  return useSelector(getselectMenuKey);
};
export const useStateOpenedMenu = () => useSelector(getStateOpenMenu);
export const useStateCurrentPath = () => useSelector(getStateCurrentPath);
export const useStateCurrFull = () => useSelector(getStateCurrFull);
export const useStateBackRoute = () => useSelector(getStateBackRoute);
export function useDispatchMenu() {
  const dispatch = useDispatch();
  const stateSetMenuList = useCallback((list: MenuItem[]) => dispatch(setUserMenu(list)), [dispatch]);
  const stateSetOpenMenuKey = useCallback((keys: string[]) => dispatch(setOpenKey(keys)), [dispatch]);
  const stateSetselectMenuKey = useCallback((keys: string[]) => dispatch(setselectMenuKey(keys)), [dispatch]);
  const stateAddOpenedMenu = useCallback((menuItem: OpenedMenu) => dispatch(addOpenedMenu(menuItem)), [dispatch]);
  const stateSetCurrentPath = useCallback((path: string) => dispatch(setCurrentPath(path)), [dispatch]);
  const stateFilterOpenMenuKey = useCallback((key: OpenedMenu[]) => dispatch(filterOpenKey(key)), [dispatch]);
  const stateStateCurrFull = useCallback((istrue: boolean) => dispatch(setCurrenFull(istrue)), [dispatch]);
  const stateSetBackRoute = useCallback((backRoute: MenuItem[]) => dispatch(setBackRoute(backRoute)), [dispatch]);
  return {
    stateSetMenuList,
    stateSetOpenMenuKey,
    stateSetselectMenuKey,
    stateAddOpenedMenu,
    stateSetCurrentPath,
    stateFilterOpenMenuKey,
    stateStateCurrFull,
    stateSetBackRoute,
  };
}
